﻿using MiniExcelLibs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Framework.ExtensionsMods.Util
{
	public class ExportExcelUtil
	{
		/// <summary>
		/// 导出Excel
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="list"></param>
		/// <param name="sheetName"></param>
		/// <param name="fileName"></param>
		public static MemoryStream ExportExcel<T>(List<T> list, string sheetName, string fileName)
		{
			return ExportExcelMini(list, sheetName, fileName);
		}

		protected static MemoryStream ExportExcelMini<T>(List<T> list, string sheetName, string fileName)
		{
			MemoryStream stream = new MemoryStream();
			stream.SaveAs(list, sheetName: sheetName);
			stream.Seek(0, SeekOrigin.Begin);
			return stream;
		}

		/// <summary>
		/// 导出多个工作表(Sheet)
		/// </summary>
		/// <param name="sheets"></param>
		/// <param name="fileName"></param>
		/// <returns></returns>
		protected static MemoryStream ExportExcelMini(Dictionary<string, object> sheets, string fileName)
		{
			MemoryStream stream = new MemoryStream();
			stream.SaveAs(sheets);
			stream.Seek(0, SeekOrigin.Begin);
			return stream;
		}
	}
}
